﻿#ifndef CAN_H
#define CAN_H

#include <QCanBusDevice>
#include <QCanBusFrame>
#include <QCloseEvent>
#include <QObject>


class Can : public QObject
{
	Q_OBJECT
public:
	Can();

	struct Settings {
		QString pluginName;
		QString deviceInterfaceName;
		QList<ConfigurationItem> configurations;
		bool useConfigurationEnabled = false;
	};

	Settings m_currentSettings;


private slots:
	void processReceivedFrames();
	void sendFrame(const QCanBusFrame& frame) const;
	void processErrors(QCanBusDevice::CanBusError) const;
	void connectDevice();
	void busStatus();
	void disconnectDevice();
	void processFramesWritten(qint64);

protected:
	//	void closeEvent(QCloseEvent* event) override;

private:
	void initActionsConnections();
	qint64 m_numberFramesWritten = 0;
	//	Ui::MainWindow* m_ui = nullptr;
	//	QLabel* m_status = nullptr;
	//	QLabel* m_written = nullptr;
	//	ConnectDialog* m_connectDialog = nullptr;
	std::unique_ptr<QCanBusDevice> m_canDevice;
	QTimer* m_busStatusTimer = nullptr;

};

#endif // CAN_H
